#include<iostream>
#include<vector>

using namespace std;

int n , k;
const int N = 15;
bool st[N];

vector<int>ret;

void dfs()
{
    if(ret.size() == k)
    {
        for(auto x : ret) cout << x << " ";
        cout << endl;
        return;
    }

    for(int i = 1;i <= n;i ++)
    {
        if(st[i]) continue;
        ret.push_back(i);
        st[i] = true;

        dfs();

        ret.pop_back();
        st[i] = false;
    }
}
int main()
{
    cin >> n >> k;
    dfs();
    return 0;
}